// 人事行政管理 / 部门管理

import r from '@/utils/request';
import type { ListResponseType, ResponseType } from '../types';

enum API {
    list = '/department/list', //部门列表
    del = '/department/delete/', //删除食材
    add = '/department/add', //添加部门
    update = '/department/update',//修改部门
}

type DepartmentlistResType = ListResponseType<{
    id: number;
    companyId: number;
    name: string;
    pid: number;
}>
type DepartmentAddRes = ResponseType<{
    id:        number;
    companyId: number;
    name:      string;
    pid:       number;
}>
export interface DepartmentAddParams {
    name: string;
    pid: number;
}
export interface DepartmentUpdateParams {
    id:number,
    name: string;
    pid: number;
}
export function DepartmentlistAPI(): Promise<DepartmentlistResType> {
    return r.get(API.list);
}

export function DepartmentAddAPI(data:DepartmentAddParams): Promise<DepartmentAddRes> {
    return r.post(API.add,data);
}
export function DepartmentUpdateAPI(data:DepartmentUpdateParams): Promise<DepartmentAddRes> {
    return r.put(API.update,data);
}

export function DelDepartmentAPI(id: number): Promise<ResponseType<null>> {
    return r.delete(API.del + id);
}

